#!/usr/bin/perl

# Perl script to generate PDF and XHTML documentation from DocBook XML sources.

my @sources = <xml/*.xml>;

print "* Building PDF output...\n";
foreach my $source (@sources) {
    $source =~ m/xml\/(.*)\.xml/;
    my $name = $1;
    `xsltproc \\
--stringparam paper.type A4 \\
--stringparam body.font.family Helvetica \\
--stringparam body.font.master 10 \\
--stringparam title.font.family "Times Roman" \\
--stringparam admin.graphics 1 \\
--output fo/$name.fo xslt/fo/docbook.xsl \\
xml/$name.xml`;
    `fop fo/$name.fo pdf/$name.pdf`;
}

print "* Building XHTML output...\n";
foreach my $source (@sources) {
    $source =~ m/xml\/(.*)\.xml/;
    my $name = $1;
    `xsltproc --output xhtml/$name.xhtml xslt/xhtml/docbook.xsl xml/$name.xml`;
}

print "* Building chunked XHTML output...\n";
foreach my $source (@sources) {
    $source =~ m/xml\/(.*)\.xml/;
    my $name = $1;
    if (not -d "xhtml-chunked/$name") {
        `mkdir xhtml-chunked/$name`;
    }
    `xsltproc --stringparam chunker.output.indent "yes" --stringparam base.dir "xhtml-chunked/$name/" xslt/xhtml/chunk.xsl xml/$name.xml`;
}

print "* Building wiki output...\n";
foreach my $source (@sources) {
    $source =~ m/xml\/(.*)\.xml/;
    my $name = $1;
    `./db2wiki ./ xml/$name.xml wiki/`;
}

print "* Completed.\n";
